package com.fz.service.project.impl;

import cn.hutool.core.convert.Convert;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.fz.common.ResponseEntity;
import com.fz.dto.project.projectWinner.ProjectWinnerAdd;
import com.fz.dto.project.projectWinner.ProjectWinnerQuery;
import com.fz.dto.project.projectWinner.ProjectWinnerUpd;
import com.fz.entity.project.ProjectWinner;
import com.fz.mapper.project.ProjectWinnerMapper;
import com.fz.service.project.ProjectWinnerService;
import com.fz.utils.JacksonUtils;
import com.fz.vo.project.projectWinner.ProjectWinnerVo;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Arrays;

/**
 * @author :xmj
 * @date :2021/3/26 上午9:53
 */
@Service
@SuppressWarnings("unchecked")
public class ProjectWinnerServiceImpl implements ProjectWinnerService {

    @Resource
    private ProjectWinnerMapper projectWinnerMapper;

    /**
     * @param pageNum            pageNum
     * @param pageSize           pageSize
     * @param projectWinnerQuery projectWinnerQuery
     * @return com.fz.common.ResponseEntity<com.fz.vo.project.projectWinner.ProjectWinnerVo>
     * @description 查询中标候选人信息分页
     * @params
     * @author xumj
     * @date 2021/3/26
     */
    @Override
    public ResponseEntity<ProjectWinnerVo> findProjectWinnerList(Integer pageNum, Integer pageSize, ProjectWinnerQuery projectWinnerQuery) {
        Page<ProjectWinner> page = new Page<>(pageNum, pageSize);
        LambdaQueryWrapper<ProjectWinner> lambdaQueryWrapper = new LambdaQueryWrapper<ProjectWinner>() {
            {
                //TODO 查询条件条件添加 ->在此拼接

            }
        };
        IPage<ProjectWinnerVo> projectWinnerList = projectWinnerMapper.findProjectWinnerList(page, lambdaQueryWrapper);
        return ResponseEntity.buildSuccess(projectWinnerList);
    }

    /**
     * @param projectWinnerAdd projectWinnerAdd
     * @return com.fz.common.ResponseEntity<com.fz.vo.project.projectWinner.ProjectWinnerVo>
     * @description 新增中标候选人信息
     * @params
     * @author xumj
     * @date 2021/3/26
     */
    @Override
    public ResponseEntity<ProjectWinnerVo> saveProjectWinner(ProjectWinnerAdd projectWinnerAdd) {
        ProjectWinner projectWinner = JacksonUtils.obj2pojo(projectWinnerAdd, ProjectWinner.class);
        projectWinnerMapper.insert(projectWinner);
        return ResponseEntity.buildSuccess();
    }

    /**
     * @param projectWinnerUpd projectWinnerUpd
     * @return com.fz.common.ResponseEntity<com.fz.vo.project.projectWinner.ProjectWinnerVo>
     * @description 修改中标候选人信息
     * @params
     * @author xumj
     * @date 2021/3/26
     */
    @Override
    public ResponseEntity<ProjectWinnerVo> updateProjectWinner(ProjectWinnerUpd projectWinnerUpd) {
        ProjectWinner projectWinner = JacksonUtils.obj2pojo(projectWinnerUpd, ProjectWinner.class);
        return ResponseEntity.buildSuccess(projectWinnerMapper.updateById(projectWinner));
    }

    /**
     * @param ids  ids 主键
     * @return com.fz.common.ResponseEntity<com.fz.vo.project.projectWinner.ProjectWinnerVo>
     * @description 删除中标候选人信息
     * @params
     * @author xumj
     * @date 2021/3/26
     */
    @Override
    public ResponseEntity<ProjectWinnerVo> delProjectWinner(String ids) {
        Long[] longs = Convert.toLongArray(ids);
        projectWinnerMapper.deleteBatchIds(Arrays.asList(longs));
        return ResponseEntity.buildSuccess();
    }
}
